unit spr_Agents;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, shbl_Directory, FIBDatabase, pFIBDatabase, ExtCtrls, 
  DB, FIBDataSet, pFIBDataSet, ActnList, Buttons, GridsEh, DBGridEh,
  StdCtrls, ComCtrls, ToolWin, DBLookupEh, Mask, DBCtrlsEh, PropFilerEh,
  PropStorageEh, XLSExportComp, DBGridEhGrouping;

type
  TsprAgents = class(TshblDirectory)
    dsReferID: TFIBIntegerField;
    dsReferAGENT_NAME: TFIBStringField;
    dsReferAGENT_RATE: TFIBBCDField;
    dsReferOPER_RATE: TFIBBCDField;
    dsReferCODE: TFIBIntegerField;
    dsReferSUPERAGENT: TFIBIntegerField;
    dsReferORGCODE: TFIBIntegerField;
    dsReferSTR_AGENT: TFIBStringField;
    dsReferORGNAME: TFIBStringField;
    eNameSearch: TEdit;
    Label10: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    DBEditEh1: TDBEditEh;
    DBEditEh4: TDBEditEh;
    DBEditEh5: TDBEditEh;
    DBEditEh6: TDBEditEh;
    DBEditEh2: TDBEditEh;
    DBEditEh3: TDBEditEh;
    Label8: TLabel;
    lcbOrg: TDBLookupComboboxEh;
    dsOrgs: TpFIBDataSet;
    dscOrgs: TDataSource;
    dsOrgsID: TFIBIntegerField;
    dsOrgsNAME: TFIBStringField;
    procedure eNameSearchChange(Sender: TObject);
    procedure dsReferBeforeEdit(DataSet: TDataSet);
    procedure dsReferBeforeInsert(DataSet: TDataSet);
    procedure lcbOrgExit(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  sprAgents: TsprAgents;

implementation

{$R *.dfm}

procedure TsprAgents.eNameSearchChange(Sender: TObject);
begin
  inherited;
  aAddSQLString.Clear;
  if eNameSearch.Text <> '' then
    aAddSQLString.Append(' and a.AGENT_NAME like rupper(''%' + eNameSearch.Text + '%'')');
  Timer1.Enabled := false;
  Timer1.Enabled := true;
end;

procedure TsprAgents.dsReferBeforeEdit(DataSet: TDataSet);
begin
  inherited;
  if dsOrgs.Active = false then dsOrgs.Open;
end;

procedure TsprAgents.dsReferBeforeInsert(DataSet: TDataSet);
begin
  inherited;
  if dsOrgs.Active = false then dsOrgs.Open;
end;

procedure TsprAgents.lcbOrgExit(Sender: TObject);
begin
  inherited;
  if (lcbOrg.KeyValue > 0) and (dsReferAGENT_NAME.AsString = '') then
    dsReferAGENT_NAME.Value := dsOrgsNAME.Value;

end;

end.
